package models

import "strings"

// MetricStatData 测点统计数据数据
type MetricStatData struct {
	Id int64 `json:"id,omitempty" gorm:"primaryKey"`

	StatType string `json:"stat_type,omitempty" gorm:"type:varchar(32);index:idx_metric,priority:2,unique"`
	MetricId int64  `json:"metric_id,omitempty" gorm:"column:metric_id;index:idx_metric,priority:1,unique"`

	ValueLast  string `json:"value_last" gorm:"type:varchar(64);"`
	ValueMin   string `json:"value_min" gorm:"type:varchar(64);"`
	ValueMax   string `json:"value_max" gorm:"type:varchar(64);"`
	ValueAvg   string `json:"value_avg" gorm:"type:varchar(64);"`
	ValueSum   string `json:"value_sum" gorm:"type:varchar(64);"`
	ValueCount string `json:"value_count" gorm:"type:varchar(64);"`

	Timestamp int64 `json:"timestamp,omitempty" gorm:"type:varchar(64);index:idx_metric,priority:3,unique"`

	CreatedAt int64 `json:"created_at,omitempty" gorm:"column:created_at;autoCreateTime:milli"`
	UpdatedAt int64 `json:"updated_at,omitempty" gorm:"column:updated_at;autoCreateTime:milli"`
}

func (u *MetricStatData) TableName() string {
	return "metric_stat_data"
}

// SplitTableName 分表
func (u *MetricStatData) SplitTableName(key string) string {
	key = strings.Replace(key, ".", "_", -1)

	return u.TableName() + "_" + key
}

type MetricStatValueData struct {
	Id int64 `json:"id" `

	StatType  string `json:"stat_type"` //统计类型，类似：1m,1h,1d
	MetricId  int64  `json:"metric_id"`
	Value     string `json:"value"`
	Timestamp int64  `json:"timestamp"`
}

type MetricValueData struct {
	MetricId  int64  `json:"metric_id"`
	Value     string `json:"value"`
	Timestamp int64  `json:"timestamp"`
}
